<link href="${rc.getContextPath()}/manage/css/dwzCustomCss/dwz.custom.css?v=${ver}" rel="stylesheet" type="text/css">
<script type="text/javascript">
$(function(){
    $("#searchTree",navTab.getCurrentPanel()).baseTreeSearch({
        inputTextId : "#searchDefectNode", //搜索框的id
        alertMsg : "<@label key='treeSearchContent.D'>请输入内容再查找</@label>", //提示内容，要考虑国际化，传自后台
        $p : navTab.getCurrentPanel()
    });
    
    $("#collapsable",navTab.getCurrentPanel())._treeCollapsable({
        $p : navTab.getCurrentPanel()
    })
    
    $("#expandable",navTab.getCurrentPanel())._treeExpandable({
        $p : navTab.getCurrentPanel()
    })
    
});

function _addTopDefectNode(_top) {
    var parentDefectNodeCode;
    if(_top && _top=='top'){
        parentDefectNodeCode = "";
    }else{
        var node = $("div#defectNodetree", navTab.getCurrentPanel()).find("div.selected").parent("li");
        if(node && node.length == 1){
            var $a = _getChildren(node);
            var defectCode = $a.attr("defectCode");
            if(defectCode && defectCode!=''){
                alertMsg.error("<@label key='defectNodeNotAdd.M'>缺陷节点不能新增子项!</@label>");
                return;
            }    
            parentDefectNodeCode =  $a.attr("code");
        }else{
            alertMsg.error("<@label key='selectNode.M'>请先选择一个节点!</@label>");
            return;
        }
    }
    $("div#defectNode_detail", navTab.getCurrentPanel()).loadUrl(hostUrl+"/defectNode/addDefectNode", {parentDefectNodeCode:parentDefectNodeCode, navTabId:'${navTabId!''}'});
}

function _deleteDefectNode(){
    var node = $("div#defectNodetree", navTab.getCurrentPanel()    ).find("div.selected").parent("li");
    if(node && node.length == 1){
        var $a = _getChildren(node);
        var _code =  $a.attr("code");
        var isLeaf = $a.attr("isLeaf")
        if(isLeaf == "no"){
            alertMsg.error("<@label key='Tree_delete_msg.D'>非叶子节点不能删除!</@label>");
            return;
        }
        alertMsg.confirm("<@label key='delete_sure.D'>确定删除</@label>【"+$a.attr("name")+"】？",{
            okCall:function(){
                $.DWZajax({
                    url:hostUrl +"/defectNode/deleteDefectNode",
                    data:{'nodeCode':_code},
                    callback:function(data){
                        alertMsg.correct("<@label key='Tree_deleteS_msg.D'>成功删除</@label>【"+$a.attr("name")+"】");
                        navTab.reload(hostUrl + "/defectNode/defectNodeTree?navTabId=${navTabId!''}");
                    }
                });
            }
        });
    }else{
        alertMsg.error("<@label key='selectNode.M'>请先选择一个节点!</@label>");
        return;
    }
}

function _editTopDefectNode() {
    var node = $("div#defectNodetree", navTab.getCurrentPanel()    ).find("div.selected").parent("li");
    if(node && node.length == 1){
        var $a = _getChildren(node);
        var _code =  $a.attr("code");
        if(!_code || _code == ''){
            alertMsg.error("<@label key='selectNode.M'>请先选择一个节点!</@label>");
            return;
        }    
    }else{
        alertMsg.error("<@label key='selectNode.M'>请先选择一个节点!</@label>");
        return;
    }
    $("div#defectNode_detail", navTab.getCurrentPanel()).loadUrl(hostUrl+"/defectNode/editDefectNode", {nodeCode:_code, navTabId:'${navTabId!''}'});
}

function viewDefectNode(_code, siteCode){
    if(_code){
        $("div#defectNode_detail", navTab.getCurrentPanel()).loadUrl(hostUrl+"/defectNode/viewDefectNode", {nodeCode:_code,siteCode:siteCode, navTabId:'${navTabId!''}'});
    }
}

function _getChildren($obj) {
    return $obj.children("div").children("a");
}

function _defectNodeCancel() {
     var ht="<div class='treeTip'><@label key='treeTips.M'>请点击左侧树形菜单进行相关操作</@label></div>";
     $("#defectNode_detail",navTab.getCurrentPanel()).html(ht);
}
</script>

<div class="pageContent">
    <div>
        <div id="defectNodetree" class="treeleft">
            <div class="mini-toolbar">
                <input type="text" id="searchDefectNode" /> <a class="buttonActive" href="javascript:void(0)" id="searchTree"><span><@label key='search.B'>搜索</@label></span>
                </a>
            </div>
            <div class="pBar pBarBorder">
                <ul class="toolBar">
                    <@buttonRight menuCode="DEFECTNODE_ADD" labelKey="addTop.B" defalutName="新增顶级项">
                        <li><a class="add" onclick="_addTopDefectNode('top');" title="<@label key='addTop.B'>新增顶级项</@label>"><span><@label key="addTop.B">新增顶级工作中心</@label></span></a></li>
                    </@buttonRight>
                    <@buttonRight menuCode="DEFECTNODE_ADD" labelKey="addchild.B" defalutName="新增子项">
                        <li><a class="add" onclick="_addTopDefectNode();" title="<@label key='addchild.B'>新增子项</@label>"><span><@label key="addchild.B">新增子项</@label></span></a></li>
                    </@buttonRight>
                    <@buttonRight menuCode="DEFECTNODE_EDIT" labelKey="edit.B" defalutName="编辑">
                        <li><a class="edit" onclick="_editTopDefectNode();" title="<@label key='edit.B'>编辑</@label>"><span><@label key="edit.B">编辑</@label></span></a></li>
                    </@buttonRight>
                    <@buttonRight menuCode="defectNode_delete" labelKey="delete.B" defalutName="删除">
                        <li><a class="delete" onclick="_deleteDefectNode();" title="<@label key='delete.B'>删除</@label>"><span><@label key="delete.B">删除</@label></span></a></li>
                    </@buttonRight>
                </ul>
            </div>
            <div id="menuBar" class="pBar pBarBorder">
                <ul class="toolBar">
                    <li><a class="collapse" id="collapsable" title="<@label key="collapseAll.D">全部收起</@label>"><span><@label key="collapse.B">收起</@label></span> </a></li>
                    <li><a class="expand" id="expandable" title="<@label key="expandAll.D">全部展开</@label>"><span><@label key="expand.B">展开</@label></span> </a></li>
                </ul>
            </div>
            <div layoutH="95">
                <ul class="tree treeFolder expand">
                    <#if defectNodeTree??> <#list defectNodeTree as defectNode>
                    <li><a code="${defectNode.nodeCode!''}" <#if defectNode.nodeTypeeCode?? && defectNode.nodeTypeeCode == 'ITEM' >style="color:#FF0011"</#if>defectCode="${defectNode.defectCode!''}" parentCode="${defectNode.parentNodeCode!''}" isLeaf="${defectNode.isLeaf?string('yes','no')}" name="${defectNode.nodeText!''}" 
                    onclick="viewDefectNode('${defectNode.nodeCode!''}', '${defectNode.siteCode!''}')">${defectNode.nodeText!''}</a> <#if defectNode.childrens??>
                        <ul><@macroDefectNodeTree children = defectNode.childrens />
                        </ul> </#if></li> </#list> </#if>
                </ul>
            </div>
        </div>
        <div id="defectNode_detail" layoutH="10" class="unitBox treeBox" >
                        <div class="treeTip"><@label key="treeTips.M">请点击左侧树形菜单进行相关操作</@label></div>
        </div>

    </div>
</div>
<!-- 递归产生树的宏定义 -->
<#macro macroDefectNodeTree children> <#if children?? && children?size gt 0> <#list children as defectNode>
<li><a code="${defectNode.nodeCode!''}" <#if defectNode.nodeTypeeCode?? && defectNode.nodeTypeeCode == 'ITEM' >style="color:#FF0011"</#if> defectCode="${defectNode.defectCode!''}" isLeaf="${defectNode.isLeaf?string('yes','no')}" name="${defectNode.nodeText!''}" parentCode="${defectNode.parenNodeCode!''}" onclick="viewDefectNode('${defectNode.nodeCode!''}', '${defectNode.siteCode!''}')">${defectNode.nodeText!''}</a> <#if defectNode.childrens??>
    <ul><@macroDefectNodeTree children = defectNode.childrens />
    </ul> </#if></li>
</#list> </#if> </#macro>
